/* ReproductionRule.java
 * 
 * Alfred Olschnoegger
 * 02.06.2008
 */

package domain.objectRules;

import java.util.Collection;
import java.util.Random;

import domain.GameObject;
import domain.Rabbit;
import domain.game.Game;
import domain.location.Position;

/**
 * TODO description
 *
 * @date 02.06.2008
 * @author Alfred Olschnoegger
 */

public class ReproductionRule extends ObjectRule {

	@Override
	public void use(GameObject obj, Game game) {
		if(obj.isActive() == true) {
			Position pos = obj.getPos();
			Collection<GameObject> objects = game.getObjectsAt(pos);
			for(GameObject partner : objects) {
				if(partner.getClass().equals(obj.getClass()) && partner.isActive() == true && obj != partner && !game.MaxRabbitsReached()) {
					if(partner.getAge() > 10) {
						Random rand = new Random();
						if(rand.nextInt() % 3 == 0)
							game.add(obj.clone());
					}
				}
			}
		}
	}
	

}


// end of ReproductionRule.java